// 周边配套
<template>
  <div id="SupportDetailsList">
    <Header :currentCity="currentCity" :cityList="cityList"></Header>
    <Crumb :crumbListData="crumbListData"></Crumb>
    <div class="SupportDetailsList_wrap">
      <div class="SupportDetailsList_wrap_tabs">
        <div class="navAcitive">
          <ul>
            <li
              v-for="(item, index) in tabList"
              :key="index"
              :class="{ activeNameTipe: activeCode == index }"
            >
              <a :href="prefixUrl + item.href">{{ item.name }}</a>
            </li>
          </ul>
        </div>
        <div>
          <div id="tabNameAll">
            <div class="PropeIndex6_p1">
              <b>{{ HouseDetail.name }}</b>
              <span
                v-html="
                  HouseDetail.saleStatus == 1
                    ? '在售'
                    : HouseDetail.saleStatus == 2
                    ? '售罄'
                    : '待售'
                "
              >在售</span>
              <span
                style="color: #ef524d; font-weight: bold; font-size: 16px"
                v-if="HouseDetail.totalPrice && HouseDetail.totalPriceMax"
              >
                参考总价：{{ HouseDetail.totalPrice }}万-{{
                HouseDetail.totalPriceMax
                }}万
              </span>
              <span
                style="font-weight: bold; font-size: 16px"
                v-else-if="HouseDetail.totalPrice || HouseDetail.totalPriceMax"
              >参考均价：{{ HouseDetail.totalPrice }}元 (房价由楼盘网智能算法统计，仅供参考)</span>
              <span style="font-weight: bold; font-size: 16px" v-else>参考均价：价格待定 (房价由楼盘网智能算法统计，仅供参考)</span>
              <div class="EstateDetail_li1_input EstateDetail_li1house">
                <input type="text" placeholder="请输入您的电话号码" maxlength="11" v-model="phone" />
                <button
                  @click="
                    clickType = 8;
                    subscribe(
                      '咨询返现详情',
                      '专业楼盘管家，深度解答！',
                      'https://mfgj.oss-cn-beijing.aliyuncs.com/upload/20211111/ec7c2095870d43459e3713b406281806.png'
                    );
                  "
                >免费咨询</button>
              </div>
            </div>
            <div id="TransactionCurve">
              <div class="prite">价格说明：暂无说明</div>
              <div id="lineAxis"></div>
            </div>
          </div>
        </div>
        <!-- 关键区域，街道，周边 -->
        <keywordBox :currentCity="currentCity" :prefixUrl="prefixUrl" :regionList="regionList"></keywordBox>
      </div>
    </div>
    <Footer :currentCity="currentCity"></Footer>

    <!-- 弹窗按钮订阅 -->
    <PopupForm
      :show="popupform.show"
      :title="popupform.title"
      :desc="popupform.desc"
      :cover="popupform.cover"
      :phone="popupform.phone"
      :smsState="popupform.smsState"
      :customTheme="popupform.customTheme"
      :background="popupform.background"
      :contentClass="popupform.contentClass"
      @phoneChange="phoneChange"
      @confirm="returnVisit"
      @cancel="
        popupform.show = false;
        popupform.background = '';
      "
    ></PopupForm>
    <!-- 订阅回调弹窗 -->
    <PopupSuccess
      :show="popupsubscribe.show"
      :cover="popupsubscribe.cover"
      :title="popupsubscribe.title"
      :desc="popupsubscribe.desc"
      @cancel="
        popupsubscribe.show = false;
        subscribeDisabled = false;
      "
    ></PopupSuccess>
  </div>
</template>
<script>
var head = {
  title: '成都✖✖✖✖✖✖✖✖✖✖', // 网页包头
  content: '成都✖✖✖✖✖✖✖✖✖✖', // 网页描述
  keywords: '成都,买房,管家,楼盘,买房网,✖✖✖✖✖✖✖✖✖✖', // 网页关键词
}
import axios from 'axios'
import u from '~/plugins/Ccom'
import * as echarts from 'echarts'
export default {
  head() {
    return {
      title: head.title,
      meta: [
        { name: 'description', content: head.content },
        { name: 'keywords', content: head.keywords },
      ],
      link: [
        {
          rel: 'stylesheet',
          href: `/css/lpgk.css?v=${new Date().getTime()}`,
        },
      ],
    }
  },
  data() {
    return {
      activeCode: 6,
      userInfo: '',
      CashBackCode: false, //用户询问
      phone: '',
      //组件订阅弹窗
      popupsubscribe: {
        show: false, //订阅数据
      },
      customTheme: 0,
      contentClass: '',
      popupform: {
        show: false, //订阅成功数据
        phone: '',
      },
      clickType: '', // 1变价提醒2开盘提醒3咨询剩余房源4订阅楼盘动态5收藏楼盘6户型分析7电话咨询（询购房资格）8询返现9专车看房10咨询返现详情11咨询房贷首付
      subscribeDisabled: false,
    }
  },
  validate(ctx) {
    return /(.*?)\.html/.test(ctx.params.id)
  },
  async asyncData(ctx) {
    var prefixUrl = ctx.prefixUrl //域名
    var currentCity = ctx.currentCity //城市定位
    var cityList = ctx.cityList //
    var crumbListData = [] //栏目信息
    var estateId = ctx.params.id ? ctx.params.id.split('.')[0] : '' //楼盘ID
    var tabList = [
      {
        name: '楼盘首页',
        href: `/lpxq/${estateId}.html`,
      },
      {
        name: '基础信息',
        href: `/lpxqxx/${estateId}.html`,
      },
      {
        name: '楼盘相册',
        href: `/lpxqxc/${estateId}.html`,
      },
      {
        name: '楼盘户型',
        href: `/lpxqhx/${estateId}.html`,
      },
      {
        name: '楼盘动态',
        href: `/lpxqdt/${estateId}.html`,
      },
      {
        name: '周边配套',
        href: `/lpxqpt/${estateId}.html`,
      },
      {
        name: '房价走势',
        href: `/lpxqzs/${estateId}.html`,
      },
      {
        name: '你问我答',
        href: `/lpxqwd/${estateId}.html`,
        aliases: 'wenda',
      },
      {
        name: '免费专车',
        href: `/mfzc/${estateId}.html`,
      },
    ]
    var HouseDetail = [] //楼盘详情数据
    var datetimes = []
    var estateDataName = ''
    var cityDataName = ''
    var regionDataName = ''
    var estateDataList = []
    var cityDataList = []
    var regionDataList = []
    // 获取楼盘详情
    var getMetro = await u.http({
      url: '/pc/houseDetail/queryHouseInfoDetailById',
      params: {
        estateId: estateId, //楼盘ID
        userId: '', //用户ID
      },
    })
    if (getMetro.code == 200) {
      HouseDetail = getMetro.data.houseInfoDetail
      head.title = `${HouseDetail.name},楼盘户型，周边配套，交通地图，${currentCity.cityName}✖✖✖✖✖✖✖✖✖✖`
      head.content = `✖✖✖✖✖✖✖✖✖✖为您提供楼盘新鲜事，为您提供${currentCity.cityName}${HouseDetail.name}楼盘楼盘新鲜事信息。房价信息，楼盘分析引导您进一步了解${HouseDetail.name}，助您做出明智的选择。`
      head.keywords = `${HouseDetail.name}楼盘动态`
      // ==========楼盘面包屑============
      var regionCode = {
        title: `${HouseDetail.regionName}楼盘`,
        href: prefixUrl + `/lpcx/${HouseDetail.regionAliases}`,
      }
      // 202112071655 sry 合并路径
      var regionA = [HouseDetail.regionAliases]
      var streetA = [HouseDetail.streetAliases]
      var nowCrumbHref = u.emptyArrayIsNull(regionA.concat(streetA))
      if (HouseDetail.streetName && HouseDetail.streetAliases) {
        var streetCode = {
          title: `${HouseDetail.streetName}楼盘`,
          href: prefixUrl + `/lpcx/${nowCrumbHref.join('-')}`,
        }
      } else {
        var streetCode = null
      }

      var houseCode = {
        title: `${HouseDetail.name}`,
        href: prefixUrl + ctx.route.path,
      }

      // 修改栏目信息
      crumbListData = [
        {
          title: `${currentCity.cityName}✖✖✖✖✖✖✖✖✖✖`,
          href: prefixUrl,
        },
      ]
      if (streetCode) {
        crumbListData.push(regionCode, streetCode, houseCode)
      } else {
        crumbListData.push(regionCode, houseCode)
      }
      // ==========楼盘面包屑============
    } else {
      // 202111091818 sry
      return ctx.redirect('/error.html')
    }

    // 获取房价走势
    var HousePrice = await u.http({
      url: '/pc/price/queryHousePriceByEstateId',
      params: {
        estateId: estateId, //楼盘ID
      },
    })
    if (HousePrice.code == 200) {
      var newData = []
      var estateData = HousePrice.data.housePriceList
      estateDataName = estateData.length > 0 ? estateData[0].houseName : ''
      estateData.forEach((item) => {
        estateDataList.push(parseInt(item.meterPrice))
      })
      var cityData = HousePrice.data.cityPriceList
      cityDataName = cityData.length > 0 ? cityData[0].cityName : ''
      cityData.forEach((item) => {
        cityDataList.push(parseInt(item.avgMeterPrice))
        newData.push(item.years)
      })
      var regionData = HousePrice.data.regionPriceList
      regionDataName = regionData.length > 0 ? regionData[0].regionName : ''
      regionData.forEach((item) => {
        regionDataList.push(parseInt(item.avgMeterPrice))
      })

      if (
        estateData.length > cityData.length &&
        estateData.length > regionData.length
      ) {
        newData = estateData.map((x) => x.years)
      }
      if (
        regionData.length > estateData.length &&
        regionData.length > cityData.length
      ) {
        newData = regionData.map((x) => x.years)
      }
    }

    return {
      tabList,
      prefixUrl,
      currentCity,
      cityList,
      crumbListData,
      estateId,
      HouseDetail,
      estateData,
      estateDataName,
      cityDataName,
      regionDataName,
      estateDataList,
      cityDataList,
      regionDataList,
      cityData,
      regionData,
      newData,
      regionList: ctx.regionList
    }
  },
  mounted() {
    this.setEcharts()
  },
  methods: {
    // 设置房价走势图标
    setEcharts() {
      // 图表
      var myChart = echarts.init(document.getElementById('lineAxis'))
      var option
      option = {
        tooltip: {
          trigger: 'axis',
        },
        legend: {
          data: [this.estateDataName, this.regionDataName, this.cityDataName],
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        toolbox: {
          feature: {},
        },
        xAxis: {
          type: 'category',
          boundaryGap: true,
          data: this.newData,
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value} 元',
          },
        },
        series: [
          {
            name: this.cityDataName,
            type: 'line',
            data: this.cityDataList,
          },
          {
            name: this.regionDataName,
            type: 'line',
            data: this.regionDataList,
          },
          {
            name: this.estateDataName,
            type: 'line',
            data: this.estateDataList,
          },
        ],
      }
      option && myChart.setOption(option)
    },
    // ==========================订阅回访消息==========================
    // 预约
    subscribe(
      title,
      desc,
      cover,
      titleend,
      customTheme,
      background,
      contentClass,
      url
    ) {
      this.popupform.show = true
      this.popupform.title = title
      this.popupform.cover = cover
      this.popupform.smsState = this.smsState
      this.popupform.desc = desc
      if (localStorage.getItem('mobile')) {
        this.popupform.phone = Number(localStorage.getItem('mobile'))
      }
      this.popupsubscribe.title = titleend
      this.popupform.customTheme = customTheme ? Number(customTheme) : 0 //是否为背景验证
      this.popupform.background = background //背景验证背景图
      this.popupform.contentClass = contentClass //活动背景图class样式
      this.popupform.url = url
    },
    // 登录成功回调
    returnVisit() {
      this.popupform.show = false
      this.subscribeDisabled = true
      let url = getCookie('token')
        ? '/app/visitRecord/addVisitRecord'
        : '/app/visitRecord/addVisitRecordByNoToken'
      u.http({
        client: true,
        url,
        headers: {
          token: getCookie('token') || '',
        },
        params: {
          clickType: this.clickType,
          phone: this.popupform.phone,
          estateId: this.estateId,
        },
      }).then((res) => {
        if (this.popupform.url) {
          location.href = this.popupform.url
          return false
        }
        this.popupsubscribe.show = true
      })
    },
    // 监听手机号
    phoneChange(e) {
      this.popupform.phone = e
    },
  },
}
</script>
